﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iCollect.CustomComponent
{
    public partial class BaseDeviceCheck : UserControl
    {
        public BaseDeviceCheck()
        {
            InitializeComponent();
        }

        public event EventHandler RaiseCustomEvent;

        protected void addCheckboxEvent()
        {
            foreach (Control control in this.Controls)
            {
                if (control is CheckBox)
                {
                    CheckBox button = (CheckBox)control;
                    button.CheckedChanged += new System.EventHandler(this.OnRaiseCustomEvent);
                }
            }
        }

        public void VTState(bool status)  
        {
            foreach (Control control in this.Controls)
            {
                if ((control is CheckBox) && (control.TabIndex < 20))
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }
            }
        }

        public void RTState(bool status)
        {
            foreach (Control control in this.Controls)
            {
                if ((control is CheckBox) && (control.TabIndex == 20))
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }
            }
        }



        public void ZEState(bool status)
        {
            foreach (Control control in this.Controls)
            {
                if ((control is CheckBox) && (control.TabIndex > 50))
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }
            }
        }

        public void TEState(bool status)
        {
            foreach (Control control in this.Controls)
            {
                if (control is CheckBox && control.TabIndex > 20 && control.TabIndex < 30)
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }

            }
        }

        public void PTState(bool status)
        {
            foreach (Control control in this.Controls)
            {
                if (control is CheckBox && control.TabIndex > 30 && control.TabIndex < 40)
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }

            }
        }

        public void FITState(bool status)
        {
            foreach (Control control in this.Controls)
            {
                if (control is CheckBox && control.TabIndex > 40 && control.TabIndex < 50)
                {
                    CheckBox checkBox = (CheckBox)control;
                    checkBox.Checked = status;
                }

            }
        }

        protected virtual void OnRaiseCustomEvent(object sender, EventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler handler = RaiseCustomEvent;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                // Format the string to send inside the CustomEventArgs parameter
                //e.Message += String.Format(" at {0}", DateTime.Now.ToString());

                //EventArgs e = new EventArgs();
                // Use the () operator to raise the event.
                handler(sender, e);
            }
        }

        public virtual List<String> getCheckedChannels()
        {
            List<String> cList = new List<string>();
            foreach (Control control in this.Controls)
            {
                if (control is CheckBox)
                {
                    CheckBox cb = (CheckBox)control;
                    if (cb.Checked)
                    {
                        cList.Add(control.Name);
                    }
                }

            }
            return cList;
        }
    }
}
